package com.ruoyi.web.controller.firststage;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.ruoyi.firststage.domain.BrandCategory;
import com.ruoyi.firststage.domain.FollowSellProduct;
import com.ruoyi.firststage.service.IBrandCategoryService;
import com.ruoyi.firststage.service.IFollowSellProductService;
import com.ruoyi.framework.web.page.PageDomain;
import com.ruoyi.framework.web.page.TableSupport;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.core.base.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;

/**
 * 跟卖商品 信息操作处理
 * 
 * @author lcx
 * @date 2018-11-24
 */
@Controller
@RequestMapping("/firststage/followSellProduct")
public class FollowSellProductController extends BaseController
{
    private String prefix = "firststage/followSellProduct";

	@Autowired
	private IFollowSellProductService FollowSellProductService;
	@Autowired
	private IBrandCategoryService brandCategoryService;



	@RequiresPermissions("firststage:followSellProduct:view")
	@GetMapping()
	public String FollowSellProduct(ModelMap mmap)
	{
		List<String> brands = brandCategoryService.selectAllBrand();
		mmap.put("brands",brands);
	    return prefix + "/list";
	}
	
	/**
	 * 查询跟卖商品列表
	 */
//	@RequiresPermissions("module:FollowSellProduct:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(FollowSellProduct FollowSellProduct)
	{
		PageDomain pageDomain = TableSupport.buildPageRequest();
		if(pageDomain.getPageNum()==null&&pageDomain.getPageSize()==null){
			PageHelper.startPage(1, 500, "");
		}else{
			startPage();
		}
        List<FollowSellProduct> list = FollowSellProductService.selectFollowSellProductList(FollowSellProduct);
		return getDataTable(list);
	}
	
	/**
	 * 新增跟卖商品
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存跟卖商品
	 */
	@RequiresPermissions("module:FollowSellProduct:add")
	@Log(title = "跟卖商品", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(FollowSellProduct FollowSellProduct)
	{		
		return toAjax(FollowSellProductService.insertFollowSellProduct(FollowSellProduct));
	}

	/**
	 * 修改跟卖商品
	 */
	@GetMapping("/edit/{fID}")
	public String edit(@PathVariable("fID") Integer fID, ModelMap mmap)
	{
		FollowSellProduct FollowSellProduct = FollowSellProductService.selectFollowSellProductById(fID);
		mmap.put("FollowSellProduct", FollowSellProduct);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存跟卖商品
	 */
	@RequiresPermissions("module:FollowSellProduct:edit")
	@Log(title = "跟卖商品", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(FollowSellProduct FollowSellProduct)
	{		
		return toAjax(FollowSellProductService.updateFollowSellProduct(FollowSellProduct));
	}
	
	/**
	 * 删除跟卖商品
	 */
	@RequiresPermissions("module:FollowSellProduct:remove")
	@Log(title = "跟卖商品", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(FollowSellProductService.deleteFollowSellProductByIds(ids));
	}
	
}
